/*
 * WorkLayer.h
 *
 *  Created on: 2010-9-6
 *      Author: try
 */

#ifndef WORKLAYER_H_
#define WORKLAYER_H_
#include "../../commons.h"
#include "../../gdiplus/gdraw.h"

using namespace std;
using namespace Thk;
using namespace Ed;

namespace Ed{
  class Element;
  class DrawPage;
}
namespace S {
  class WorkPage;
  class Shape;
  class ControlPoint;

  class WorkLayer: public Layer {
    public:
      WorkLayer(WorkPage* page);
      virtual ~WorkLayer();

      /**
       * 切换光标
       */
      void switchCursor();
      /**
       * 将选中元素移动到顶层
       */
      void adjustToTop();
      /**
       * 将选中元素移动到底层
       */
      void adjustToBottom();
      /**
       * 将选中元素下移一层
       */
      void adjustToNext();
      /**
       * 将选中元素上移一层
       */
      void adjustToUp();
      /**
       * 合并选中图形
       */
      void merge();
      /**
       * 取消组合
       */
      void unmerge();
      /**
       * 删除图形
       */
      void deleteShape(Shape* s);

      /**
       * 图形数量
       */
      int getShapeNums(){
        return allShapes.size();
      }

      bool isDrawing(){
        return isDrawingFlag;
      }

      void setDrawing(bool b){
        isDrawingFlag = b;
      }

    private:
      //选择模式光标
      DefaultCursor* selectModeCursor;
      //绘图模式光标
      DefaultCursor* drawModeCursor;

      //所有图形
      std::vector<Shape* > allShapes;
      typedef std::vector<Shape* >::iterator ShapeIterator;

      //是否正在画图
      bool isDrawingFlag;

      //变换操作控制点
      ControlPoint* transformControlPoint;

      /**
       * 画椭圆
       */
      void drawEllipse(real ex, real ey);

      /**
       * 画矩形
       */
      void drawRectangle(real ex, real ey);

      /**
       * 画图形
       */
      void WorkLayer::drawShape(Shape* s, bool drawing = true);

    protected:
      bool event(const Event* e);
      void mousePressEvent(const MouseEvent* e);
      void mouseMoveEvent(const MouseEvent* e);
      void mouseLeaveEvent(const MouseEvent* e);
      void mouseReleaseEvent(const MouseEvent* e);
      void mouseDoubleClickEvent(const MouseEvent* e);
      void mouseWheelEvent(const WheelEvent* e);
      void paintEvent(const PaintEvent* e);


      void keyPressEvent(const KeyEvent* e);
      void keyReleaseEvent(const KeyEvent* e);

  };
}
#endif /* WORKLAYER_H_ */
